package cn.nfwx.tv.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.nfwx.tv.R;
import cn.nfwx.tv.okhttp.UrlHelper;
import cn.nfwx.tv.util.GlideUtil;

/**
 * Created by zhouzechao on 2017/11/22.
 */

public class ClipImageAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {

    private float perWidth = 14;
    private double ceilWidthCount; // 高值长度的个数
    private int lastWidth;
    private String mClipPath;

    public ClipImageAdapter() {
        super(R.layout.item_clip_image);
    }

    @Override
    protected void convert(BaseViewHolder helper, Object item) {
        final ImageView imageView = helper.getView(R.id.clip_image);
        if (ceilWidthCount > 0) {
            ceilWidthCount--;
            int width = (int) Math.ceil(perWidth);
            if (helper.getLayoutPosition() == getData().size() - 1) {
                width = width + lastWidth;
            }
            imageView.getLayoutParams().width = width;
        } else {
            int width = (int) Math.floor(perWidth);
            if (helper.getLayoutPosition() == getData().size() - 1) {
                width = width + lastWidth;
            }
            imageView.getLayoutParams().width = width;
        }
        //imageView.setImageResource(R.mipmap.head);
        if (item instanceof Long) {
            GlideUtil.loadImage(helper.itemView.getContext(), UrlHelper.getThumbUrl(mClipPath, (Long) item), imageView);
        } else if(item instanceof String){
            GlideUtil.loadImage(helper.itemView.getContext(), (String) item, imageView);
        }
    }

    public void setPerWidth(float perWidth) {
        this.perWidth = perWidth;
    }

    public void setCeilWidthCount(double ceilWidthCount) {
        this.ceilWidthCount = ceilWidthCount;
    }

    public void setLastWidth(int lastWidth) {
        this.lastWidth = lastWidth;
    }

    public void setClipPath(String clipPath) {
        mClipPath = clipPath;
    }
}
